CC = $(CROSS)g++
AR = $(CROSS)ar -r
SR = $(CROSS)g++ -shared
LD = $(CROSS)ld 

TARGET   := $(BUILDIN)

SUBDIRS = 

SRC_FILES := $(wildcard *.cpp)
OBJ_FILES := $(SRC_FILES:.cpp=.o)

SUB_FILES := $(addsuffix /$(BUILDIN),$(SUBDIRS))
EXT_FILES := 

subdir     := $(addprefix build_,$(SUBDIRS) )
clean_dirs := $(addprefix clean_,$(SUBDIRS) )

CFLAGS   +=

LD_FLAGS +=

export CROSS
export BUILDIN
export CFLAGS
export PWD

# default rule
default: all

# non-phony targets
$(TARGET): $(OBJ_FILES)
	@echo "LD   $(TARGET)"
	$(LD) -r -o $@ $(OBJ_FILES) $(SUB_FILES) $(EXT_FILES)

$(OBJ_FILES): %.o:%.cpp
	$(CC) $(CFLAGS) -c -o $@ $<

$(SUBDIRS):
	make -C $@

$(subdir):
	@echo "CC  $@"
	$(MAKE) -C $(patsubst build_%,%,$@)

$(clean_dirs):
	$(MAKE) -C $(patsubst clean_%,%,$@) clean

# phony rules
.PHONY: all 
all: $(subdir) $(TARGET)

.PHONY: clean
clean:
	rm -rf *.o
